var nav = document.querySelectorAll(".ul_title > li > span");
var main = document.querySelectorAll(".text_inner > div");
for(var i= 0; i<nav.length; i++){
    nav[i].index = i;
    nav[i].addEventListener('click',function(){
        for(var j = 0; j<nav.length; j++){
            nav[j].classList.remove("active1");
            main[j].classList.remove("active");
        }
        this.classList.add("active1");
        main[this.index].classList.add("active");
    })
}








var input1 =document.querySelector("#ipt1");
var text = document.querySelector("#text");
var anniu = document.querySelector("#anniu");
var text2 = document.querySelector("#text2");
anniu.addEventListener("click",function(){
    var new_obj2 = document.createElement("div");
    //创建节点
    var new_obj = document.createElement("p");
    //创建任务内容节点
    var zi = document.createElement("text");
    //将input标签添加到
    zi.innerHTML = input1.value;
    //添加节点（删除的图片）
    var op = document.createElement("img");
    //添加完成任务的节点
    var dui = document.createElement("span");
    //添加时间任务的节点
    var time1 = document.createElement("i");
    //将节点的图片引进过来
    op.setAttribute("src","img/img-1.png");
    //操作节点（删除）

    if(input1.value !=""){
        op.setAttribute("onclick","javascript:this.parentNode.parentNode.removeChild(this.parentNode);");
        var yi = 'yixuan';
        dui.addEventListener('click',function(){
            if(yi == 'yixuan'){
                yi = "wexian";
            }else {
                yi = "yixuan";
            }

            if(yi == 'wexian'){
                dui.innerHTML = "√";
                zi.style.color = "#999";
                zi.style.textDecoration = "line-through";
                //text2.prepend(new_obj);

            }else {
                dui.innerHTML = "";
                zi.style.color = "#000";
                zi.style.textDecoration = "none";
            }

            if(dui.innerHTML == "√"){
                new_obj2.innerHTML += new_obj.innerHTML;
                //text2.innerHTML = text.innerHTML;
            }
        });

        var kk = new Date();
        time1.innerHTML = kk.getFullYear()+"-"+(kk.getMonth()+1)+"-"+kk.getDate()+" "+kk.getHours()+":"+kk.getMinutes()+":"+kk.getSeconds()+"";
        //将节点在div的第一个子标签前添加
        text.prepend(new_obj);
        text2.prepend(new_obj2);
        //p标签添加完成任务的样式
        new_obj.appendChild(dui);
        //p标签添加a标签任务内容
        new_obj.appendChild(zi);
        //将图片在节点p的最后一个标签添加删除
        new_obj.appendChild(op);
        //添加创建事项的时间
        new_obj.appendChild(time1);
        //清除input的内容
        input1.value = '';

    }









});














//回车事件
var input = document.getElementById("ipt1");
input.addEventListener("keyup", function(event) {
    event.preventDefault();
    if (event.keyCode === 13) {
        document.getElementById("anniu").click();
    }
});